package com.yugao.fintech.antelope.pay.mch.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.antelope.base.exception.enums.GlobalErrorEnum;
import com.yugao.fintech.antelope.base.log.OperateLog;
import com.yugao.fintech.antelope.pay.common.service.PayWayService;
import com.yugao.fintech.antelope.pay.model.entity.PayWay;
import com.yugao.fintech.antelope.pay.model.rqrs.PayWayQL;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;

import java.util.List;

/**
 * 支付方式管理类
 */
@RestController
@RequestMapping("/mgr/payWay")
public class PayWayController {
    @Autowired
    private PayWayService payWayService;

    @GetMapping("/page")
    @RamResource(action = "pay:payWay:list", name = "查询支付方式列表", type = ActionType.READ)
    public Resp<IPage<PayWay>> page(PayWayQL query) {
        return Resp.ok(payWayService.pagePayWay(query));
    }

    @GetMapping("/listPayWay")
    @RamResource(action = "pay:payWay:list", name = "查询支付方式列表", type = ActionType.READ)
    public Resp<List<PayWay>> listPayWay(PayWayQL query) {
        return Resp.ok(payWayService.listPayWay(query));
    }


    @GetMapping("/getByWayCode")
    @RamResource(action = "pay:payWay:get", name = "查询支付方式详情", type = ActionType.READ)
    public Resp<PayWay> get(@RequestParam("wayCode") String wayCode) {
        return Resp.ok(payWayService.getById(wayCode));
    }


    //	@PreAuthorize("hasAuthority('ENT_PC_WAY_ADD')")
    @PostMapping("/save")
    @OperateLog(summary = "新增支付方式")
    @RamResource(action = "pay:payWay:save", name = "保存支付方式方式", type = ActionType.WRITE)
    public Resp<?> save(@RequestBody PayWay payWay) {
        payWayService.savePageWay(payWay);
        return Resp.ok();
    }

    @PostMapping("/update")
    @RamResource(action = "pay:payWay:update", name = "更新支付方式", type = ActionType.WRITE)
    @OperateLog(summary = "更新支付方式")
    public Resp<?> update(@RequestBody PayWay payWay) {
        boolean result = payWayService.updateById(payWay);
        if (!result) {
            return Resp.fail(GlobalErrorEnum.OPERATION_FAIL_UPDATE);
        }
        return Resp.ok();
    }

    @DeleteMapping("/deleteByWayCode")
    @RamResource(action = "pay:payWay:delete", name = "删除支付方式", type = ActionType.WRITE)
    @OperateLog(summary = "删除支付方式")
    public Resp<?> delete(@RequestParam("wayCode") String wayCode) {
        payWayService.deletePayWay(wayCode);
        return Resp.ok();
    }


}
